package main

import (
	"fmt"
	"log"

	"github.com/go-xorm/core"
	"github.com/go-xorm/xorm"
	_ "github.com/lib/pq"
)

const (
	host     = "localhost"
	port     = 5432
	user     = "admin"
	password = "admin"
	dbname   = "test"
)

type People struct {
	Id   int `xorm:"autoincr"`
	Name string
	Age  string
	Age2 int
}

var engine *xorm.Engine

func main() {
	//https://www.kancloud.cn/kancloud/xorm-manual-zh-cn/
	psqlInfo := fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s sslmode=disable", host, port, user, password, dbname)
	var err error
	engine, err = xorm.NewEngine("postgres", psqlInfo)
	engine.SetSchema("public1")
	defer engine.Close()

	if err != nil {
		log.Panicln(err)
	} else {
		log.Println("ok")
	}

	engine.ShowSQL(true)
	engine.Logger().SetLevel(core.LOG_DEBUG)
	//	engine.DBMetas()
	//	engine.TableInfo()
	sql := `SELECT * FROM public1.people `
	//	var people []People
	people := []People{}
	engine.Sql(sql).Find(&people)
	log.Println(people)
}
